package org.interfaceadaptation.test.notnull;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;

public class ArrayCompoundInstrospector implements CompoundInstrospector {

	@Override
	public Collection<Object> getSubElements(Object element) {
		Collection<Object> subElement = new ArrayList<Object>();
	    for(int i=0; i < numSubElements(element); i++) {
	    	subElement.add(Array.get(element, i));
	    }
		return subElement;
	}

	@Override
	public int numSubElements(Object element) {
		
		return Array.getLength(element);
	}

	@Override
	public boolean emptyIsNull() {
		return true;
	}

	@Override
	public boolean isCompoundInstrospectorFor(Object element) {
		return element.getClass().isArray();
	}
	


}
